< previous page page_280 next page >

Page 280
indicates that you wish to import function "otherfunc" from mydll.dll and that you will refer to it in your VB program by the name "myfunc."
On the other hand,
Declare Sub myfunc Lib "mydll.dll" ()
indicates that you wish to import function "myfunc" from mydll.dll and refer to it in your VB program by the same name.
In the first case, the dynamic link library mydll.dll must export function "otherfunc" or the operation will failVB will not be able to find the function. In the second case, mydll.dll must export function "myfunc."
The Declare Statement in Depth
The Visual Basic documentation offers the following syntax for the Declare statement:
[Public | Private] Declare Sub name Lib "libname" [Alias "aliasname"]
[([arglist])]

[Public | Private] Declare Function name Lib "libname" [Alias "aliasname"]
[([arglist])] [As type]
Let's look at this one element at a timesee Table T1-1 below.
[Public I Private]The Declare statement may be prefixed by the keyword Public or Private. The default is Public. There are two general approaches for handling Declare statements in an application. One is to make all of the Declare statements public and place them in a standard module where they can be shared by all the other modules in the application. The other is to make the statements private and place the declarations needed for each module in that module. Larger applications tend to use the former approach. Declare statements in form and class modules must be private.

Declare

The keyword that indicates that this statement is used to define access to an API or DLL function.

(table continued on next page)

 
< previous page page_280 next page >